﻿using Serialization.Script;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using DrawableObjects.Actors.Aircrafts;
using System.Collections.Generic;
using Sirian.DrawableObject.Actors;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GlobalGameClasses;
using DrawableObjects.Actors.Aircrafts.Controller;
using Serialization;

namespace SirianTestEnvironment
{
    
    
    /// <summary>
    ///This is a test class for StraightLine_FormationTest and is intended
    ///to contain all StraightLine_FormationTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FormationTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        private static Bounding visibleArea = new Bounding(new Vector2(0, 0), 1200, 800, true);
        private static Bounding useableArea = new Bounding(new Vector2(-301, -300), 1802, 1101, true);
        private static List<Aircraft> aircrafts = new List<Aircraft>();
        private static List<Vector2> pathPoints = new List<Vector2>();
        private static Path basePath;

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            pathPoints.Add(new Vector2(0, 0));
            basePath = new Path(pathPoints);

            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            form.Visible = false;
            form.ShowInTaskbar = false;
            PresentationParameters param = new PresentationParameters();
            param.DeviceWindowHandle = form.Handle;
            param.IsFullScreen = false;
            GraphicsDevice device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef, param);
            GlobalGameClasses.GlobalGameValues.Values.graphicsDevice = device;
            GlobalGameClasses.GlobalGameValues.Values.spriteBatch = new SpriteBatch(device);
            GlobalGameValues.Values.content.addContent("aircraft_enemy1", null, new Texture2D(device, 1, 1));
            GlobalGameValues.Values.content.addContent("aircraft_enemy2", null, new Texture2D(device, 1, 1));
            GlobalGameValues.Values.content.addContent("aircraft_enemy3", null, new Texture2D(device, 1, 1));
            GlobalGameValues.Values.content.addContent("aircraft_enemy4", null, new Texture2D(device, 1, 1));
            GlobalGameValues.Values.content.addContent("aircraft_enemy5", null, new Texture2D(device, 1, 1));
        }
        //
        //Use ClassCleanup to run code after all tests in a class have run
        [ClassCleanup()]
        public static void MyClassCleanup()
        {
            GlobalGameValues.Values.achievementsUnlocked = new List<Achievement>();
            GlobalGameValues.Values.content = new ContentCollection();
            GlobalGameValues.Values.difficulty = null;
            GlobalGameValues.Values.errorWriter = null;
            GlobalGameValues.Values.gameTime = new GameTime();
            GlobalGameValues.Values.GlobalStrings = new StringContainer();
            GlobalGameValues.Values.graphicsDevice = null;
            GlobalGameValues.Values.score = new InterfaceComponents.HUDWrapper<int>(new List<InterfaceComponents.HUDComponent>());
            GlobalGameValues.Values.soundPlayer = null;
            GlobalGameValues.Values.spriteBatch = null;
            GlobalGameValues.Values.volume_Music = 0;
            GlobalGameValues.Values.volume_soundEffect = 0;
        }
        //
        //Use TestInitialize to run code before running each test
        [TestInitialize()]
        public void MyTestInitialize()
        {
            aircrafts.Add(FabricatableAircraft.GET_ENEMY_1(Matrix.Identity));
            aircrafts.Add(FabricatableAircraft.GET_ENEMY_1(Matrix.Identity));
            aircrafts.Add(FabricatableAircraft.GET_ENEMY_1(Matrix.Identity));
            aircrafts.Add(FabricatableAircraft.GET_ENEMY_3(Matrix.Identity));
            aircrafts.Add(FabricatableAircraft.GET_ENEMY_2(Matrix.Identity));
            aircrafts.Add(FabricatableAircraft.GET_ENEMY_5(Matrix.Identity));
            aircrafts.Add(FabricatableAircraft.GET_ENEMY_4(Matrix.Identity));
        }
        //
        //Use TestCleanup to run code after each test has run
        [TestCleanup()]
        public void MyTestCleanup()
        {
            aircrafts.Clear();
        }
        //
        #endregion


        /// <summary>
        ///A test for setFormation
        ///</summary>
        [TestMethod()]
        public void StraightLine_setFormationTest()
        {
            StraightLine_Formation target = new StraightLine_Formation();
            target.setFormation(aircrafts, basePath, visibleArea, useableArea);
            Rectangle targetArea = new Rectangle(0,-300,1200,301);
            Vector2 pos1;
            Vector2 pos2;
            Point actualPosition; 
            foreach (Aircraft aircraft in aircrafts)
            {
                pos1 = aircraft.getGamePosition();
                actualPosition = new Point((int)pos1.X, (int)pos1.Y);
                Assert.IsTrue(targetArea.Contains(actualPosition));
                Assert.IsTrue(aircraft.controller is AIControlledAircraft_PathGuided);
                foreach (Aircraft aircraft2 in aircrafts)
                {
                    pos2 = aircraft2.getGamePosition();
                    Assert.IsTrue((pos1 - pos2).Length() <= aircraft.boundingSphere.Radius + aircraft2.boundingSphere.Radius);
                }
            }
        }
        /// <summary>
        ///A test for setFormation
        ///</summary>
        [TestMethod()]
        public void VFormation_setFormationTest()
        {
            V_Formation target = new V_Formation();
            target.setFormation(aircrafts, basePath, visibleArea, useableArea);
            Rectangle targetArea = new Rectangle(0, -300, 1200, 301);
            Vector2 pos1;
            Vector2 pos2;
            Point actualPosition;
            foreach (Aircraft aircraft in aircrafts)
            {
                pos1 = aircraft.getGamePosition();
                actualPosition = new Point((int)pos1.X, (int)pos1.Y);
                Assert.IsTrue(targetArea.Contains(actualPosition));
                Assert.IsTrue(aircraft.controller is AIControlledAircraft_PathGuided);
                foreach (Aircraft aircraft2 in aircrafts)
                {
                    pos2 = aircraft2.getGamePosition();
                    Assert.IsTrue((pos1 - pos2).Length() <= aircraft.boundingSphere.Radius + aircraft2.boundingSphere.Radius);
                }
            }
        }
        /// <summary>
        ///A test for setFormation
        ///</summary>
        [TestMethod()]
        public void VictoryOrDeath_setFormationTest()
        {
            Victory_or_Death_Formation target = new Victory_or_Death_Formation();
            target.setFormation(aircrafts, basePath, visibleArea, useableArea);
            Rectangle targetArea = new Rectangle(0, -300, 1200, 301);
            Vector2 pos1;
            Vector2 pos2;
            Point actualPosition;
            foreach (Aircraft aircraft in aircrafts)
            {
                pos1 = aircraft.getGamePosition();
                actualPosition = new Point((int)pos1.X, (int)pos1.Y);
                Assert.IsTrue(targetArea.Contains(actualPosition));
                Assert.IsTrue(aircraft.controller is AIControlledAircraft_PathGuided);
                foreach (Aircraft aircraft2 in aircrafts)
                {
                    pos2 = aircraft2.getGamePosition();
                    Assert.IsTrue((pos1 - pos2).Length() <= aircraft.boundingSphere.Radius + aircraft2.boundingSphere.Radius);
                }
            }
        }
        /// <summary>
        ///A test for setFormation
        ///</summary>
        [TestMethod()]
        public void WallOfDeathLeft_setFormationTest()
        {
            WallOfDeath_Formation_Left target = new WallOfDeath_Formation_Left();
            target.setFormation(aircrafts, basePath, visibleArea, useableArea);
            Rectangle targetArea = new Rectangle(-300, 0, 301, 800);
            Vector2 pos1;
            Vector2 pos2;
            Point actualPosition;
            foreach (Aircraft aircraft in aircrafts)
            {
                pos1 = aircraft.getGamePosition();
                actualPosition = new Point((int)pos1.X, (int)pos1.Y);
                Assert.IsTrue(targetArea.Contains(actualPosition));
                Assert.IsTrue(aircraft.controller is AIControlledAircraft_PathGuided);
                foreach (Aircraft aircraft2 in aircrafts)
                {
                    pos2 = aircraft2.getGamePosition();
                    Assert.IsTrue((pos1 - pos2).Length() <= aircraft.boundingSphere.Radius + aircraft2.boundingSphere.Radius);
                }
            }
        }
        /// <summary>
        ///A test for setFormation
        ///</summary>
        [TestMethod()]
        public void WallOfDeathRight_setFormationTest()
        {
            WallOfDeath_Formation_Right target = new WallOfDeath_Formation_Right();
            target.setFormation(aircrafts, basePath, visibleArea, useableArea);
            Rectangle targetArea = new Rectangle(1199, 0, 301, 800);
            Vector2 pos1;
            Vector2 pos2;
            Point actualPosition;
            foreach (Aircraft aircraft in aircrafts)
            {
                pos1 = aircraft.getGamePosition();
                actualPosition = new Point((int)pos1.X, (int)pos1.Y);
                Assert.IsTrue(targetArea.Contains(actualPosition));
                Assert.IsTrue(aircraft.controller is AIControlledAircraft_PathGuided);
                foreach (Aircraft aircraft2 in aircrafts)
                {
                    pos2 = aircraft2.getGamePosition();
                    Assert.IsTrue((pos1 - pos2).Length() <= aircraft.boundingSphere.Radius + aircraft2.boundingSphere.Radius);
                }
            }
        }
    }
}
